package Demo01.test1;
import java.util.Arrays;
import java.util.Comparator;
class Book {
    private String title;
    private double price;
    public Book(String title,double price){
        this.title = title;
        this.price = price;
    }
    public String getTitle(){
        return title;
    }
    public double getPrice(){
        return price;
    }
    public String toString(){
        return "【Book】图书名称：" + this.title +"、图书价格" + this.price + "\n";
    }
}
public class ComparatorDemo01 {
    private static void main(String[] args) throws Exception{
        Book books [] = new Book[]{
                new Book("Java从入门到项目实战", 99.8),
                new Book("Python从入门到项目实战", 89.7),
                new Book("Go从入门到项目实战", 96.3)};
        Comparator<Book> comparator = ( o1, o2) -> {
            if (o1.getPrice() > o2.getPrice()){
                return 1;
            }else if (o1.getPrice() < o2.getPrice()){
                return -1;
            }else {
                return 0;
            }
        };
        Arrays.sort(books, comparator);
        System.out.println(Arrays.toString(books));
    }
}
